package com.wyl.mine.setting

import com.lzg.extend.BaseResponse
import com.lzg.extend.JsonConvert
import com.lzg.extend.toDisposables
import com.lzy.okgo.OkGo
import com.lzy.okrx2.adapter.ObservableBody
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.base.MINE_ABOUT_US
import com.wyl.libbase.base.NormalActivity
import com.wyl.mine.R
import kotlinx.android.synthetic.main.about_us_activity.*


class AboutUsActivity : NormalActivity() {
    override fun getLayoutId(): Int = R.layout.about_us_activity

    override fun initView() {
        titlebar.setListener { _, action, _ ->
            when (action) {
                CommonTitleBar.ACTION_LEFT_BUTTON -> onBackPressed()
                else -> {
                }
            }
        }

    }

    override fun loadData() {
        OkGo.post<BaseResponse<Map<String, String>>>(MINE_ABOUT_US)
            .converter(object : JsonConvert<BaseResponse<Map<String, String>>>() {})
            .adapt(ObservableBody<BaseResponse<Map<String, String>>>())
            .map { it.data }
            .subscribe({
                address.text = it["website"]
                copyright.text = it["copyright"]
                tel.text = it["phone"]
                email.text = it["mailbox"]
            }, {
                onError(it)
                it.printStackTrace()
            }).toDisposables(disposables)
    }
}